<style>
    td{
        height: 30px !important;
        line-height: 30px !important;
    }
    .yutfgg{
        border-bottom: 1px solid #e6e6e6;width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
    }
</style>
<div class="layui-row">
    <div class="layui-card-header">
        <div class="left tbt">
            共{$lists->total()}条记录  <span class="x-red" id="onsel" style="display: none;">已选择<span id="onselnum"></span>条</span>
        </div>
        {if !$isearch}
        <div class="right">
            <button class="layui-btn layui-btn-primary addline" onclick="addline()">新增条目</button>
            <button class="layui-btn layui-btn-primary selobj" onclick="sel()" data-type="sel">批量选择</button>
            <button class="layui-btn layui-btn-danger del" onclick="del()">删除</button>
        </div>
        {else}
        <div class="right">
            <form action="{:url('cartoon/details')}" id="search" method="get" class="layui-form layui-col-space5 hide">
                <input type="hidden" name="search" value="1">
                <input type="hidden" name="id" value="{$item.id}">
                <input type="hidden" name="sel" value="{$sel}">
                <input type="hidden" name="year">
                <input type="hidden" name="staff">
                <div class="layui-inline layui-show-xs-block">
                    <select name="search_type" lay-filter="search_type">
                        <option value="">筛选条件</option>
                        <option value="year" {if request()->get('search_type') eq 'year'}selected{/if}>按年份</option>
                        <option value="typec1" {if request()->get('search_type') eq 'typec1'}selected{/if}>只看正常刊号</option>
                        <option value="typec2" {if request()->get('search_type') eq 'typec2'}selected{/if}>只看休刊</option>
                        <option value="typec3" {if request()->get('search_type') eq 'typec3'}selected{/if}>只看合刊停售</option>
                        <option value="tdcyr" {if request()->get('search_type') eq 'tdcyr'}selected{/if}>按特定封面人物</option>
                    </select>
                </div>
            </form>
        </div>
        {/if}
    </div>
    <div class="layui-card-body layui-card-body-table">
        <table class="layui-table layui-form">
            <thead>
            <tr>
                {if !$isearch}
                <th></th>
                {/if}
                <th>首更日期</th>
                <th>星期</th>
                <th>杂志刊号</th>
                <th>总话数</th>
                <th>单行本话数</th>

                <th>标题（中）</th>
                <th>标题（日）</th>


                <th>对应TV话数</th>
                <th>对应TV标题</th>
                <th>单行本封面人物</th>
                <th>单行本发售日期</th>
            </tr>
            </thead>
            <tbody id="comicsbody">
            {php}
            $i = 0;
            {/php}
            {foreach $datas as $key=>$val}
            {php}
            $i +=1;
            $yueshu = $i%2;
            $classname = "color".$yueshu;
            {/php}
            {foreach $val as $k=>$item}
            {php}
            if($item['add_time']){
            $year = date("Y",$item['add_time']);
            }else{
            $year = "";
            }
            {/php}
            <tr class="comicslist tr_{$item.id} {$classname} {if $item.display eq 0} dls{/if}" data-year="{$year}" data-key="{$i}">
                {if !$isearch}
                <td>
                    <a href="javascript:;" class="editbtn" onclick="xadmin.open(null,'{:url("comics/post")}?id={$item.id}')">编辑</a>
                    <div style="display: none;" class="selone"><input type="checkbox" name="selone" value="{$item.id}" lay-filter="selone" lay-skin="primary" ></div>
                </td>
                {/if}
                <td class="btr">
                    {if $item.add_time}
                    {:date("Y年n月j日",$item['add_time'])}
                    {else}
                    /
                    {/if}
                </td>
                <td class="btr">
                    {if $item.add_time}
                    周{:formatWeek(date('w',$item['add_time']))}
                    {else}
                    /
                    {/if}
                </td>
                <td class="btr">
                    {if $item.typec}
                    {if $item.typec eq 1}
                    {if $item.year}
                    {$item.year}年
                    {/if}
                    {if ($item.num1) OR ($item.num2)}
                    第
                    {if $item.num1}{$item.num1}{/if}
                    {if $item.num2}·{$item.num2}{/if}
                    号{if $item.num2}(合并){/if}
                    {/if}
                    {elseif $item.typec eq 2}
                    休刊
                    {else}
                    因上次合刊而停售
                    {/if}
                    {else}
                    /
                    {/if}
                </td>
                <td class="btr">
                    {if $item.words1}
                    File{$item.words1}
                    {else}
                    /
                    {/if}
                </td>
                <td class="btr">
                    {if $item.comics_rolls}
                    第{$item.comics_rolls}卷File{$item.comics_rolls_file}
                    {else}
                    /
                    {/if}
                </td>

                <td class="btr">
                    {if $item.title}
                    {$item.title}
                    {else}
                    /
                    {/if}
                </td>
                <td class="btr">
                    {if $item.title_jp}
                    {$item.title_jp}
                    {else}
                    /
                    {/if}
                </td>
                {if ($key eq 1) AND ($k eq 0)}
                <td rowspan="{$arrayNum}" class="nobtr" style="padding: 0;vertical-align: top">

                    {foreach $dytvs as $kkk=>$vvv}
                        {php}
                            $height = (48 * $jjarray[$kkk]) + ceil($jjarray[$kkk])-1;
                        {/php}
                        <div class="yutfgg" style="height: {$height}px;">
                            {if $vvv.fan_cat}
                            {switch $vvv.fan_cat}
                            {case 1}第{$vvv.quarter}季,第{$vvv.words1}话{/case}
                            {case 2}第{$vvv.words1}话{/case}
                            {case 3}
                            {if $vvv.special_cat}
                            第{$vvv.words1}话~第{$vvv.words2}话
                            {else}
                            第{$vvv.words2}部
                            {/if}
                            {/case}
                            {/switch}
                            {else}
                            第{$vvv.words1}话
                            {/if}
                        </div>
                    {/foreach}

                </td>
                <td rowspan="{$arrayNum}" class="nobtr" style="padding: 0;vertical-align: top">
                    {foreach $dytvs as $kkk=>$vvv}
                    {php}
                    $height = (48 * $jjarray[$kkk]) + ceil($jjarray[$kkk])-1;
                    {/php}
                    <div class="yutfgg" style="height: {$height}px;">
                        {$vvv.title}
                    </div>
                    {/foreach}
                </td>
                {/if}
                {if $k==0}

                <td rowspan="{:count($val)}" class="nobtr">
                    {if $item.thumb}
                    {$item.thumb}
                    {else}
                    /
                    {/if}
                </td>
                <td rowspan="{:count($val)}" class="nobtr">
                    {if $item.release_date}
                    {:date("Y年n月j日",$item['release_date'])}
                    {else}
                    /
                    {/if}
                </td>
                {/if}
            </tr>
            {/foreach}
            {/foreach}
            </tbody>
        </table>
    </div>
    <div class="layui-card-body ">
        {$lists|raw}
    </div>

</div>
<script>
    $(function () {
        var trlen = $('.comicslist').length;
        for(var i=0;i<trlen;i++){
            var year = $('.comicslist').eq(i).data("year")

            if(year){

                if($('.comicslist').eq(i+1).length>0){
                    var nextyear = $('.comicslist').eq(i+1).data("year")
                    if(year!=nextyear){
                        $('.comicslist').eq(i).addClass("redcolor")
                    }
                }
            }
        }
    })
    function del() {
        var id;
        let seltype = $('.selobj').data("type")
        if(seltype==="sel"){
            id = [$('[name="selone"]').last().val()]
        }else{
            id = getselall()
        }

        layer.confirm("{:lang('del.confirm')}",{icon: 3, title:'{:lang("tips")}'},function (index) {
            layer.close(index);
            request("POST",'{:url("comics/del")}',{
                id:id
            },function (res) {
                window.location.reload()
            })

        })
    }
    function addline() {
        request("POST",'{:url("comics/add")}',{work_id:id},function (res,msg) {
            var html
            html +=`<tr class="tr_${res.id}">`
            html +='<td>'
            html +=`<a href="javascript:;" class="editbtn" onclick="xadmin.open('{$item.title}','{:url("comics/post")}?id=${res.id}')">编辑</a>`
            html +=`<div style="display: none;" class="selone"><input type="checkbox" name="selone" value="${res.id}" lay-skin="primary" /></div>`
            html +='</td>';
            for(var i = 1;i<=11;i++){
                if(i==4){
                    html +=`<td>第${res.words1}话</td>`
                }else{
                    html +=`<td>/</td>`
                }
            }
            html +=`</tr>`
            window.location.reload();
            // $('#comicsbody').append(html)

        })
    }

</script>